package com.ydd.controller.admin;

import com.ydd.dto.CateDTO;
import com.ydd.dto.CategoryPageQueryDTO;
import com.ydd.entity.YddCate;
import com.ydd.mapper.YddArticleMapper;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.YddCateService;
import com.ydd.vo.CateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description TODO
 * @Author fang
 * @Date 2023-05-29 16:48
 */
@Api(tags = "内容管理-分类管理")
@RestController
@RequestMapping("/admin/ydd_cate")
@Slf4j
public class YddCateController {
    @Autowired
    YddCateService yddCateService;

    /**
     * 通过分类id查询分类详细
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("分类详细")
    public Result<YddCate> row( Long id){
        log.info("通过id查询分类详细:{}",id);

       YddCate cate =  yddCateService.findRow(id);
        return Result.success(cate);
    }

    /**
     * 分类列表分页查询
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("分类列表分页")
    public Result<PageResult> list(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("分类列表分页查询:{}",categoryPageQueryDTO);
        PageResult pageResult = yddCateService.list(categoryPageQueryDTO);

        return Result.success(pageResult);
    }

    @GetMapping("/del")
    @ApiOperation("GET分类删除")
    public Result del(String id) throws Exception {
        log.info("GET分类删除：{}",id);

        yddCateService.del(id);

        return Result.success();
    }

    /**
     * POST分类修改
     *
     * @param
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("POST分类修改")
    public Result update(@RequestBody  CateDTO cateDTO){
        log.info("POST分类修改：{}",cateDTO);

        yddCateService.update(cateDTO);

        return Result.success();
    }

    /**
     * 文章添加
     * @param cateDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("POST分类添加")
    public Result add(@RequestBody  CateDTO cateDTO){
        log.info("POST分类添加（文章添加）：{}",cateDTO);
        yddCateService.add(cateDTO);
        return Result.success();
    }

    @GetMapping("/all")
    @ApiOperation("GET分类列表-全部")
    public Result<List<CateVO>> all(){
        log.info("GET分类列表-全部");
        List<CateVO> cateVOList = yddCateService.all();
        return Result.success(cateVOList);


    }

}
